package com.mocoop.activity;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.mocoop.activity.MocoopTabHost.MocoopTabHostListener;
import com.mocoop.entity.PageInfoEntity;
import com.mocoop.ui.MocoopFragment;

public class MocoopTabHostSingletonActivity extends MocoopSingletonActivity implements MocoopTabHostListener {
	private LinearLayout footBar;
	private MocoopTabHost mocoopTabHost;

	public LinearLayout getFootBar() {
		return footBar;
	}


	public void setFootBar(LinearLayout footBar) {
		this.footBar = footBar;
	}

	@Override
	public MocoopTabHost getMocoopTabHost() {
		return mocoopTabHost;
	}


	public void setMocoopTabHost(MocoopTabHost mocoopTabHost) {
		this.mocoopTabHost = mocoopTabHost;
	}


	@Override
	public void initView() {
		setContentView(R.layout.activity_tabhost_singleton);
		fragmentsLayout = (RelativeLayout) findViewById(R.id.fragmentsLayout);
		footBar = (LinearLayout) findViewById(R.id.footBar);
		mocoopTabHost = new MocoopTabHost(this);
		mocoopTabHost.setMocoopTabHostListener(this);
	}

	
	@Override
	public void changeItemListener(int id) {

	}
	
	public void changeCurrentWebView(final PageInfoEntity pageInfoEntity) {
		runOnUiThread(new Runnable() {
			@Override
			public void run() {
				currentFragment.showLoadView(null);
				currentFragment.setPageInfo(pageInfoEntity);
				currentFragment.loadURL(getBASE_URL() + pageInfoEntity.getUrl());
			}
		});
	}

	@Override
	public void jumpNewPage(final PageInfoEntity pageInfoEntity) {
		if(!isJumpEnd)return;
		runOnUiThread(new Runnable() {
			@Override
			public void run() {
				footBar.setVisibility(View.GONE);
				MocoopTabHostSingletonActivity.super.jumpNewPage(pageInfoEntity);
			}
		});

	}

	@Override
	public void goBack(MocoopFragment.MyAnimationCallBack animationCallBack) {
		if(!isJumpEnd)return;
		runOnUiThread(new Runnable() {

			@Override
			public void run() {
				if (history.size() <= 1) {
					dialog();
				} else {
					if (history.size() == 2) {
						footBar.setVisibility(View.VISIBLE);
					}
					MocoopTabHostSingletonActivity.super.goBack(null);
				}
			}
		});

	}
	
	@Override
	public boolean backToSpecifyPage(final String targetURL) {
		runOnUiThread(new Runnable() {
			
			@Override
			public void run() {
				if(!MocoopTabHostSingletonActivity.super.backToSpecifyPage(targetURL)){
					footBar.setVisibility(View.VISIBLE);
				}
			}
		});
		return false;
	}

	@Override
	public void messageCountController(final String tabName, final String msg) {
		
	}

}
